-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow retrieving the queue signal in a sink when using crossbeam-channel feature #600
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified because it did not pass CI with clippy error: doc list item missing indentation
Hi, Thanks for the PR. This Pr exposes more of Rodio's internals which will make it harder to make changes to rodio in the future, which makes me hesitant to merge this. Maybe there is another way. Could you explain why you need this? |
Hi @dvdsk, Thank you for your response, there are two cases, and I use both:
Currently, if I use The new function It becomes faster starting up the program and make the program less memory consuming than loading all files at startup.
In my case, I can now use crossbeam::channel::select! {
recv(receiver_from_append_with_signal) -> msg => receiver_from_append_with_signal = my_sink.append_with_signal(MySource::load()),
recv(receiver_from_another_thread_sending_messages) -> msg => my_sink.set_volume(0.5),
} In this case, it is possible to block the thread as with This also means we could have two sinks, in two different threads, where the first could send a message to the second to lower the volume of the second until the first ended playing. |
Your first use case (a good one) is in the same category to #506. It seems a good idea to overhaul/redesign the Sink to better support these use-cases. Regarding the second use-case, can you give me a a little more information? Are you trying to do a cross-fade effect? |
Ok, I will explain my own use case if it helps understand it better. First of all, this is not to do a cross-fade effect, I already use My application works with at least two Sinks working in different threads (It can't be synchronous for reasons not linked with rodio). The first thread will handle music in the background, the Sink will continuously play. The second thread will handle the "event" music, the Sink will play only several sounds and will last like 30 seconds each time when something is triggered by my users. The "event"s are more important than the music in the background, therefore I want at this moment, the first thread Sink volume can be set to 0.5, but not stopping playing, and at the end of the "event", the background can be set back to volume 1.0. In fact, my overall issue is to make both first case and second case work together, I need both in my project, and I found out the little change I made here made it easy. Hope it is more understandable with that case ! |
@AlbanWS would adding an https://docs.rs/rodio/latest/rodio/source/struct.EmptyCallback.html source after your sound effect work? The empty callback could send a message using an mpsc for example |
b10961c
to
a7f67b3
Compare
(Same person, different account) Indeed ! It would fit well, thank you for all ! |
0ee0413
to
073fdb1
Compare
Hi,
This commit creates a new
Sink::append_with_signal
method and makeSink::append
a wrapper function without breaking change.It only "works" with the
crossbeam-channel
feature flag becausecrossbeam::channel::Receiver
implementsClone
but notstd::sync::mpsc::Receiver
.append_with_signal
will be useful in case we have to do something at the end of aSource
inside aSink
.